<?php
namespace App\Admin\Controllers\Traits\WxSettingTraits;

use App\Admin\Renderable\DayTaskRender;
use App\Admin\Renderable\IconRender;
use App\Admin\Renderable\PlateRender;
use App\Jobs\UserBgColorUpdateJob;
use App\Models\WxClause;
use App\Models\WxIcon;
use App\Models\WxPlate;
use App\Models\WxTask;
use App\Wen\Utils\AdminUtils;
use App\Wen\Utils\FieldUtils;
use App\Wen\Utils\GatewayUtils;
use App\Wen\Utils\Settings;
use App\Wen\Utils\SiteUtils;
use Dcat\Admin\Form\NestedForm;
use Dcat\Admin\Layout\Content;
use Dcat\Admin\Widgets\Form;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;

trait formPageMineTrait{
    public function index_pagemine(Content $content)
    {
        return $content->title('“我”相关')
//            ->body($this->buildPreviewButton())
//            ->body($this->newline())
            ->body(
                <<<HTML
<div class="card">{$this->form_pagemine()->render()}</div>
HTML
            );
    }
    protected function form_pagemine(){
        $form = new Form();
        $form->confirm('您确定要提交表单吗？', 'content');
        $form->disableResetButton();
        $form->tab('我', function (Form $form) {
            $form->multipleSelectTable('app_mine_header_icon', '头部左右侧')
                ->title('图标库')
                ->max(2)
                ->from(IconRender::make())
                ->model(WxIcon::class, 'id', 'name', 'selectTable:formPageMineTrait:app_mine_header_icon')
                ->help('添加两个，分别是左右侧，小程序不显示右侧， <a href="'.admin_url('settings/icons').'" target="_blank">管理图标库>></a><a href="https://doc.minisns.cn/doc/70/" target="_blank" style="color: red;">（ps：如何控制顺序?）&nbsp;</a>')
                ->default(Settings::get('app_mine_header_icon', ''));

            $form->textarea('app_user_introduce', '默认简介')->help('用户默认简介')->default(Settings::get('app_user_introduce', '这个人很懒，还没有简介'));
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">格子菜单：除了强制显示以外，其他菜单需要一定的条件才会显示，例如：在用户购物车里有商品时才显示购物车</div>';
            }, '');
            $form->html(function () {
                return '<img src="https://img.mini.minisns.cn/hbx/tabbar/bg/mine_tip.jpg" style="width: 200px;border-radius: 10px;"/>';
            }, '');
            $form->checkbox('app_user_grid_display_force', '强制显示')->options(['my_wallet'=>'我的钱包', 'my_used'=>'我的闲置', 'my_organize_bureau' => '我的组局' ,'my_vip'=>'我的会员', 'my_shop_order'=>'我的买入', 'my_shop_bag'=>'我的购物车', 'my_voter' => '我的选票', 'my_pets_adoption'=>'领养、送养'])->default(Settings::get('app_user_grid_display_force', ['my_shop_order', 'my_shop_bag']));
            $form->checkbox('app_user_grid_three_display_force', '强制显示')->help('ta人视角')->options(['my_used' => 'Ta的闲置', 'my_voter' => 'Ta的选票', 'my_pets_adoption'=>'Ta的送养'])->default(Settings::get('app_user_grid_three_display_force', ['my_pets_adoption']));
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">内容列表样式</div>';
            }, '');
            $form->radio('app_user_list_style', '内容列表样式')->options([0=>'默认',1=>'瀑布流'])->default(Settings::get('app_user_list_style', 0));
        });

        $form->tab('左侧栏', function (Form $form) {
            $form->listbox('app_user_left_panel', '左侧栏菜单')->options([
                'my_wallet'=>'我的钱包',
                'payment_password'=>'支付密码',
                'consumption_records'=>'消费记录',
                'organize_bureau_center' => '活动中心',
                'organize_club_settle_in' => '俱乐部入驻',
                'my_order'=>'我的买入',
                'my_sales'=>'我的卖出',
                'my_shopping_bag'=>'我的购物袋',
                'address'=>'收货地址',
                'my_certification'=>'我的认证',
                'my_members'=>'我的会员',
                'my_circle'=>'我的圈子',
                'my_team'=>'我的团队',
            ])->help('右边代表选中')->customFormat(function ($value){
                return Settings::get('app_user_left_panel', [], true);
            });
        });

        $form->tab('资料', function (Form $form) {
            $form->list('app_user_labels','用户标签')->default(Settings::get('app_user_labels', []));
        });

        $form->tab('等级', function (Form $form) {
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">综合考虑: 不做太复杂的权限控制，为了常常遇到的审查，可以对敏感功能做一些限制</div>';
            }, '');
            $form->radio('app_user_lv_watch_video', '视频浏览')->options([0=>'未登录',1=>'lv1', 2=>'lv2', 3=>'lv3', 4=>'lv4', 5=>'lv5', 6=>'lv6'])->help('未达到该等级时，则不会显示视频贴')->default(Settings::get('app_user_lv_watch_video', 0));
            $form->radio('app_user_lv_publish_video', '发布视频')->options([0=>'未登录',1=>'lv1', 2=>'lv2', 3=>'lv3', 4=>'lv4', 5=>'lv5', 6=>'lv6'])->help('未达到该等级时，则不会显示发布视频的按钮')->default(Settings::get('app_user_lv_publish_video', 1));
            $form->radio('app_user_lv_open_chat', '发起聊天')->options([0=>'未登录',1=>'lv1', 2=>'lv2', 3=>'lv3', 4=>'lv4', 5=>'lv5', 6=>'lv6'])->help('未达到该等级时，则不会在ta人主页显示私信按钮')->default(Settings::get('app_user_lv_open_chat', 1));
        });

        $form->tab('认证', function (Form $form) {
            $form->radio('app_user_authenticate_permissions', '发起认证所需权限')->options(FieldUtils::userPermissions('user_authenticate'))->default(Settings::get('app_user_authenticate_permissions', 0));
            $form->divider();
            $form->radio('app_user_authenticate_img_require', '发起认证必须传图')->options([0=>'关闭', 1=>'开启'])->default(Settings::get('app_user_authenticate_img_require', 1));
            $form->list('app_user_authenticate_img_tip', '上传图片提示语')->default(Settings::get('app_user_authenticate_img_tip', ['1.个人自媒体用户可上传身份证正反面照片或其他app个人中心认证页面', '2.企业或其他主体可上传营业执照或其他app个人中心认证页面']));
        });

        $form->tab('登录', function (Form $form) {
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">系统会自动处理在当前平台不支持的方式，比如在小程序不支持苹果登录，h5页面也不支持苹果登录等</div>';
            }, '');
            $form->html(function () {
                return '<div>---------------------------------------------------------------------------------</div>';
            }, '<b>小程序</b>');
            $form->checkbox('app_login_style', '登录方式')->options([0=>'微信', 2=>'手机号'])->default(Settings::get('app_login_style', ''));
            $form->checkbox('app_register_style', '注册方式')->options([0=>'微信', 2=>'手机号'])->default(Settings::get('app_register_style', ''));
            $form->html(function () {
                return '<div>---------------------------------------------------------------------------------</div>';
            }, '<b>H5</b>');
            $form->checkbox('app_h5_login_style', '登录方式')->options([0=>'微信', 2=>'手机号', 3=>'QQ'])->default(Settings::get('app_h5_login_style', ''));
            $form->checkbox('app_h5_register_style', '注册方式')->options([0=>'微信', 2=>'手机号', 3=>'QQ'])->default(Settings::get('app_h5_register_style', ''));
            $form->html(function () {
                return '<div>---------------------------------------------------------------------------------</div>';
            }, '<b>安卓App</b>');
            $form->checkbox('app_app_android_login_style', '登录方式')->options([0=>'微信', 2=>'手机号', 3=>'QQ'])->default(Settings::get('app_app_android_login_style', ''));
            $form->checkbox('app_app_android_register_style', '注册方式')->options([0=>'微信', 2=>'手机号', 3=>'QQ'])->default(Settings::get('app_app_android_register_style', ''));
            $form->html(function () {
                return '<div>---------------------------------------------------------------------------------</div>';
            }, '<b>苹果App</b>');
            $form->checkbox('app_app_ios_login_style', '登录方式')->options([0=>'微信', 1=>'苹果', 2=>'手机号', 3=>'QQ'])->default(Settings::get('app_app_ios_login_style', ''));
            $form->checkbox('app_app_ios_register_style', '注册方式')->options([0=>'微信', 1=>'苹果', 2=>'手机号', 3=>'QQ'])->default(Settings::get('app_app_ios_register_style', ''));
            $form->html(function () {
                return '<br/>';
            }, '');
            $form->divider();
            $form->radio('app_login_force', '强制登录')->options([0 => '关闭', 1=> '开启'])->help('若开启，移动端所有页面都强制登录，不登录则浏览不了所有页面')->default(Settings::get('app_login_force', 0));
            $form->image('app_login_bg', '登录背景图')->help('建议和默认图片大小。 <a href="https://img.mini.minisns.cn/2023/03/25/68b11834f85f49711ae1ba875f7d7ab1.jpg" download="app_login_bg.jpg" target="_blank" style="color: steelblue">点击下载默认图</a>')->url('files/uploads')->uniqueName()->autoUpload()->default(Settings::get('app_login_bg', 'https://img.mini.minisns.cn/2023/03/25/68b11834f85f49711ae1ba875f7d7ab1.jpg'));
            $form->radio('app_login_bg_scroll', '背景')->options([0=>'静止', 1=>'滚动'])->default(Settings::get('app_login_bg_scroll', 1));
            $form->divider();

            $form->text('default_user_name', '用户默认昵称')->default(Settings::get('default_user_name', '微信用户'));
            $form->image('user_background_maps', '用户默认背景')->help('<a href="https://img.mini.minisns.cn/icons/back.jpg" download="user_background_maps.jpg" target="_blank" style="color: steelblue">点击下载默认图</a>')->url('files/uploads')->uniqueName()->autoUpload()->default(Settings::get('user_background_maps', 'https://img.mini.minisns.cn/icons/back.jpg'));
            $form->multipleSelectTable('app_login_default_plates', '用户默认选择的板块')->title('板块库')
                ->max(10)
                ->from(PlateRender::make())
                ->model(WxPlate::class, 'id', 'plate_name', 'selectTable:formPageMineTrait:app_login_default_plates')
                ->help('也就是第一次注册后，默认选择的板块，<a href="'.admin_url('plate').'" target="_blank">管理板块>></a><a href="https://doc.minisns.cn/doc/70/" target="_blank" style="color: red;">（ps：如何控制顺序?）&nbsp;</a>')->default(Settings::get('app_login_default_plates', ''));
            $form->text('app_login_first_welcome_title', '欢迎语-标题')->help('第一次注册时以系统通知的方式发送给客户')->default(Settings::get('app_login_first_welcome_title', '欢迎来到'.Settings::get('app_title', '宠也')));
            if(__system_is_model_enable('laradocs', 'dcat-neditor')){
                $form->neditor('app_login_first_welcome', '欢迎语-内容')->help('以系统通知的方式')->default(Settings::get('app_login_first_welcome', '祝你在这里找到自己的朋友，并且玩的开心'));
            }else{
                $form->editor('app_login_first_welcome', '欢迎语-内容')->width(4)->help('以系统通知的方式')->default(Settings::get('app_login_first_welcome', '祝你在这里找到自己的朋友，并且玩的开心'));
            }
        });

        $form->tab('匿名', function (Form $form) {

            $form->table('anonymous_name_avatar','匿名资料库', function (NestedForm $table) {
                $table->text('name', '用户名')->placeholder('如：阿白，momo')->required();
                $table->image('avatar', '头像')->url('files/uploads')->uniqueName()->autoUpload();
            })->default(Settings::get('anonymous_name_avatar', ''));

        });

        $form->tab('签到与任务', function (Form $form) {
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">小提示: 不多不少，添加7个，分别是星期一到星期日</div>';
            }, '');
            $form->table('app_user_sign','签到配置', function (NestedForm $table) {
                $table->select('type', '类型')->options(FieldUtils::getGiftTypes())->default(0)->required();
                $table->number('num', '数量')->default(1)->required();
            })->default(Settings::get('app_user_sign', ''));
            $form->multipleSelectTable('app_sign_day_task', '每日任务')
                ->title('每日任务库')
                ->max(100)
                ->from(DayTaskRender::make())
                ->model(WxTask::class, 'id', 'name', 'selectTable:formPageMineTrait:app_sign_day_task')
                ->help('可至<a href="'.admin_url('tasks/day').'" target="_blank">[任务系统-每日任务]</a>进行管理或者新添加<a href="https://doc.minisns.cn/doc/70/" target="_blank" style="color: red;">（ps：如何控制顺序?）&nbsp;</a>')
                ->default(Settings::get('app_sign_day_task', ''));
        });

        $form->tab('帮助与反馈', function (Form $form) {
            $form->listbox('app_qa_types', '常见问题')->options(FieldUtils::getQuestionTypes())->customFormat(function ($value){
                return Settings::get('app_qa_types', []);
            })->help('右边代表选中，请至<a href="'.admin_url('qa/question').'" target="_blank">用户管理-帮助</a>进行管理帮助问题');
        });

        $form->tab('收益排行榜', function (Form $form) {
            $form->image('app_earnings_rank_bg', '背景图')->help('建议图片 600*518 px。 <a href="https://img.mini.minisns.cn/images/rank/rank_bg.png" download="app_share_vip_img.jpg" target="_blank" style="color: steelblue">点击下载默认图</a>')->url('files/uploads')->uniqueName()->autoUpload()->default(Settings::get('app_earnings_rank_bg', 'https://img.mini.minisns.cn/images/rank/rank_bg.png'));
        });

        $form->tab('手机号弹窗', function (Form $form) {
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">暂时仅可在小程序完成</div>';
            }, '');
            $form->image('img_get_phone_popup', '获得手机号弹窗')->help('默认的获得手机号图片：<a href="https://img.mini.minisns.cn/images/phone.jpg" download="dafault.jpg" target="_blank" style="color: steelblue">点击下载默认图</a>')->uniqueName()->url('files/uploads')->autoUpload()->default(Settings::get('img_get_phone_popup', 'https://img.mini.minisns.cn/images/phone.jpg'));
            $form->listbox('app_force_phone_pages', '弹窗页面')->options([1=>'首页',3=>'发布', 4=>'消息', 5=>'我的', 6=>'圈子页', 7=>'话题页', 9=>'内容详情页', 10=>'搜索', 14=>'登录页', 15=>'聊天详情', 16=>'更新资料',17 => '新建圈子页', 18=>'举报', 40 =>'提交反馈页', 98=>'闲置发布'])->customFormat(function ($value){
                return Settings::get('app_force_phone_pages', []);
            })->help('右边代表选中');
            $form->radio('app_force_phone_hard', '强制获取')->options([0=>'关闭', 1=>'开启'])->help('默认用户可以关闭，如果强制的话用户就关闭不了，必须获取手机号')->default(Settings::get('app_force_phone_hard', 0));
        });

        $form->tab('关于我们', function (Form $form) {
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">小提示: 我希望minisns可以得到你的支持，这也是间接在维护你自己的权益，市面上很多产品都停更，坚持不了多久，我希望minisns更man一点</div>';
            }, '');
            $form->radio('app_user_about_mine_minisns_show', '展示“迷你SNS驱动”')->options([0=>'不展示', 1=>'展示'])->help('未授权用户强制展示，已获得授权用户可以选择是否展示')->default(Settings::get('app_user_about_mine_minisns_show', 1));
            $form->text('app_user_about_mine_minisns_id', '官网用户id')->help('可去宠也小程序[我]tab查看，配置了用户id，则可以产生有效推广')->default(Settings::get('app_user_about_mine_minisns_id', 11691));

            $form->divider();

            $form->table('app_user_about_mine_list','展示列表', function (NestedForm $table) {
                $table->text('name', '文本')->default('文字');
                $table->radio('type', '类型')->options(FieldUtils::getUrlTypes())->default(0);
                $table->text('target', '跳转id')->help('<a href="https://doc.minisns.cn/doc/44/" target="_blank">路径大全</a>');
            })->default(Settings::get('app_user_about_mine_list', ''));
        });

        $form->tab('名片', function (Form $form) {
            $form->radio('app_user_qrcode_way', '名片生成')->options([1=>'方案一', 2=>'方案二'])->help('鉴于总有人说名片生成不了，如果默认的方案一生成不了，请切换方案二，方案二需要把官方的cdn域名: img.mini.minisns.cn 加入小程序的域名白名单')->default(Settings::get('app_user_qrcode_way', 1));
        });

        $form->tab('用户海报', function (Form $form) {
            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">路径：/pagesB/playbill/userPoster</div>';
            }, '');

            $form->html(function () {
                return '<a href="https://img.mini.minisns.cn/images/bg/user_poster.png" target="_blank">查看效果</a>';
            }, '');

            $form->table('app_share_poster','图片样式', function (NestedForm $table) {
                $table->text('text1', '文本一')->default('我的二维码');
                $table->text('text2', '文本二')->default('邀请你加入女厕');
                $table->text('text3', '文本三')->default('躺着就能赚钱');
                $table->image('url', '背景')->help('建议图片 560*800 px。 <a href="https://img.mini.minisns.cn/2022/11/04/cc09ed8e1e17689b81a27aec1e471fe8.png" download="app_share_vip_img.jpg" target="_blank" style="color: steelblue">点击下载默认图</a>')->url('files/uploads')->uniqueName()->autoUpload();
            })->default(Settings::get('app_share_poster', ''));
        });

        $form->tab('钱包-充值', function (Form $form) {
            $form->table('app_balance_recharge_list','充值套餐', function (NestedForm $table) {
                $table->number('balance', '增加余额');
                $table->number('rmb', '消耗人民币')->help('注意，配置的价格不能有重复');
            })->default(Settings::get('app_balance_recharge_list', ''));
            $form->select('app_balance_recharge_clause', '《余额服务协议》')->options(WxClause::pluck('title', 'id'))->help('<a href="'.admin_url('clause').'" target="_blank">进入条款管理</a>')->default(Settings::get('app_balance_recharge_clause', 0));
            $form->select('app_balance_recharge_child_refund_clause', '《未成年人退款申请》')->options(WxClause::pluck('title', 'id'))->help('<a href="'.admin_url('clause').'" target="_blank">进入条款管理</a>')->default(Settings::get('app_balance_recharge_child_refund_clause', 0));
        });

        $form->tab('钱包-提现', function (Form $form) {

            $form->radio('is_withdrawal', '是否开启提现')->options([1=>'是', 0=>'否'])->help('提现申请管理：<a href="'.admin_url('withdrawal').'" target="_blank">[运营管理]-[提现]</a>')->default(Settings::get('is_withdrawal', 1));
            $form->rate('app_withdrawal_platform_percent', '提现手续费')->default(Settings::get('app_withdrawal_platform_percent', 10.0));

            $form->divider();

            $form->html(function () {
                return '<div style="background-color: powderblue;color: #414750;padding: 10px;border-radius: 5px;">1、提现到微信：需要在<a style="color: blue;" href="https://pay.weixin.qq.com/index.php/public/product/detail?pid=108&productType=0&category=2" target="_blank">微信商户平台</a>开通“商家转账到零钱”产品，若未开通，则需要你根据提现申请，手动打款
<br/>
2、提现到支付宝：需要在<a href="https://b.alipay.com/page/product-mall/product-detail/I1080300001000046143?" target="_blank" style="color: blue;">支付宝商家平台</a>开通“转账到支付宝账户”产品，若未开通，则需要你根据提现申请，手动打款<br/>
3、开启<a href="'.admin_url('settings/pay').'" target="_balck" style="color: blue;">[全局配置-支付-微信-《商家转账到零钱》产品]</a>的开关，支付宝同理
</div>';
            }, '');

            $form->checkbox('app_balance_withdrawal_way', '提现方式')->options(['wechat'=>'提现到微信零钱', 'alipay'=>'提现到支付宝'])->default(Settings::get('app_balance_withdrawal_way', ['wechat', 'alipay']));
            $form->divider();

            $form->radio('app_balance_withdrawal_force_bind_phone', '强制绑定手机号')->options([0=>'不强制', 1=>'强制'])->default(Settings::get('app_balance_withdrawal_force_bind_phone', 0));
            $form->radio('app_balance_withdrawal_force_real_name', '强制实名')->options([0=>'不强制', 1=>'强制'])->default(Settings::get('app_balance_withdrawal_force_real_name', 0));
            global $__MINI_GLOBAL_TENANT_ID__;
            $form->radio('app_balance_withdrawal_force_subscribe_mp', '强制关注公众号')->options([0=>'不强制', 1=>'强制'])->help($__MINI_GLOBAL_TENANT_ID__ > 0 ? '必须开启服务器地址' : '必须开启服务器地址，具体请去[全局配置-支付-微信-公众号]')->default(Settings::get('app_balance_withdrawal_force_subscribe_mp', 0));

            $form->divider();
            $form->number('app_balance_withdrawal_day_times', '每日最多几次提现')->default(Settings::get('app_balance_withdrawal_day_times', 3));
            $form->number('app_balance_withdrawal_max_once', '一次最多提现')->default(Settings::get('app_balance_withdrawal_max_once', 200));
            $form->number('app_balance_withdrawal_min_once', '一次最少提现')->default(Settings::get('app_balance_withdrawal_min_once', 1));
            $form->divider();
            $form->list('app_balance_withdrawal_tips','补充说明')->default(Settings::get('app_balance_withdrawal_tips', []));
        });

        $form->tab('自助解封', function (Form $form) {
            $form->decimal('app_unban_one_hour_balance', '解除封号消耗余额/小时')->help('请自行换算到一天多少钱，一天24小时')->default(Settings::get('app_unban_one_hour_balance', 1.0));
            $form->decimal('app_unmute_one_hour_balance', '解除禁言消耗余额/小时')->help('请自行换算到一天多少钱，一天24小时')->default(Settings::get('app_unmute_one_hour_balance', 0.5));
        });

        $form->tab('付费获取联系方式', function (Form $form) {
            $form->rate('app_contact_pay_platform_percent', '平台分成')->default(Settings::get('app_contact_pay_platform_percent', 30.0));
        });

        $form->action('settings/action/pagemine');
        return $form;
    }

    public function pagemine(Request $request){
        $app_balance_recharge_list = AdminUtils::_table_data($request->input('app_balance_recharge_list'));
        if($app_balance_recharge_list){
            $app_balance_recharge_list_arr = json_decode($app_balance_recharge_list, true);
            $cache_list =  [];
            foreach ($app_balance_recharge_list_arr as $item){
                if(in_array($item['rmb'], $cache_list)){
                    return $this->response()->error('充值套餐的人民币不能有重复');
                }else if($item['rmb'] <= 0){
                    return $this->response()->error('充值套餐的人民币不能为0');
                }else{
                    $cache_list[] = $item['rmb'];
                }
            }
        }

        SiteUtils::forget_config_data();

        Settings::set('app_user_introduce', $request->input('app_user_introduce'), true);
        Settings::set('app_user_grid_display_force', $request->input('app_user_grid_display_force'), true);
        Settings::set('app_user_grid_three_display_force', $request->input('app_user_grid_three_display_force'), true);

        Settings::set('app_user_authenticate_permissions', $request->input('app_user_authenticate_permissions'), true);
        Settings::set('app_user_authenticate_img_require', $request->input('app_user_authenticate_img_require'), true);
        Settings::set('app_user_authenticate_img_tip', AdminUtils::list_fiele_process($request->input('app_user_authenticate_img_tip')), true);

        Settings::set('app_user_list_style', $request->input('app_user_list_style'), true);
        Settings::set('app_user_labels', AdminUtils::list_fiele_process($request->input('app_user_labels')), true);


        Settings::set('app_mine_header_icon', AdminUtils::_multipleSelectTable_order_process('selectTable:formPageMineTrait:app_mine_header_icon', $request->input('app_mine_header_icon')) , true);
        // 3

        $app_login_style = $request->input('app_login_style');
        $app_login_style_ = [];
        if($app_login_style){
            foreach ($app_login_style as $i){
                if($i === null){
                    continue;
                }
                $app_login_style_[] = (int)$i;
            }
        }

        $app_h5_login_style = $request->input('app_h5_login_style');
        $app_h5_login_style_ = [];
        if($app_h5_login_style){
            foreach ($app_h5_login_style as $i){
                if($i === null){
                    continue;
                }
                $app_h5_login_style_[] = (int)$i;
            }
        }

        $app_app_android_login_style = $request->input('app_app_android_login_style');
        $app_app_android_login_style_ = [];
        if($app_app_android_login_style){
            foreach ($app_app_android_login_style as $i){
                if($i === null){
                    continue;
                }
                $app_app_android_login_style_[] = (int)$i;
            }
        }


        $app_app_ios_login_style = $request->input('app_app_ios_login_style');
        $app_app_ios_login_style_ = [];
        if($app_app_ios_login_style){
            foreach ($app_app_ios_login_style as $i){
                if($i === null){
                    continue;
                }
                $app_app_ios_login_style_[] = (int)$i;
            }
        }

        $app_register_style = $request->input('app_register_style');
        $app_register_style_ = [];
        if($app_register_style){
            foreach ($app_register_style as $i){
                if($i === null){
                    continue;
                }
                $app_register_style_[] = (int)$i;
            }
        }

        $app_h5_register_style = $request->input('app_h5_register_style');
        $app_h5_register_style_ = [];
        if($app_h5_register_style){
            foreach ($app_h5_register_style as $i){
                if($i === null){
                    continue;
                }
                $app_h5_register_style_[] = (int)$i;
            }
        }

        $app_app_android_register_style = $request->input('app_app_android_register_style');
        $app_app_android_register_style_ = [];
        if($app_app_android_register_style){
            foreach ($app_app_android_register_style as $i){
                if($i === null){
                    continue;
                }
                $app_app_android_register_style_[] = (int)$i;
            }
        }

        $app_app_ios_register_style = $request->input('app_app_ios_register_style');
        $app_app_ios_register_style_ = [];
        if($app_app_ios_register_style){
            foreach ($app_app_ios_register_style as $i){
                if($i === null){
                    continue;
                }
                $app_app_ios_register_style_[] = (int)$i;
            }
        }

        Settings::set('app_login_style', $app_login_style_, true);
        Settings::set('app_h5_login_style', $app_h5_login_style_, true);
        Settings::set('app_app_android_login_style', $app_app_android_login_style_, true);
        Settings::set('app_app_ios_login_style', $app_app_ios_login_style_, true);

        Settings::set('app_register_style', $app_register_style_, true);
        Settings::set('app_h5_register_style', $app_h5_register_style_, true);
        Settings::set('app_app_android_register_style', $app_app_android_register_style_, true);
        Settings::set('app_app_ios_register_style', $app_app_ios_register_style_, true);

        Settings::set('app_user_left_panel', $request->input('app_user_left_panel'), true);

        Settings::set('app_login_force', $request->input('app_login_force'), true);
        Settings::set('app_login_bg_scroll', $request->input('app_login_bg_scroll'), true);
        Settings::set('app_login_bg', $request->input('app_login_bg'), true);

        Settings::set('anonymous_name_avatar', AdminUtils::_table_data($request->input('anonymous_name_avatar')), true);

        Settings::set('default_user_name', $request->input('default_user_name'), true);
        if($request->input('default_user_name') == '微信用户' || $request->input('default_user_name') == '普通用户'){
            Settings::set('default_user_name_', '', true);
        }else{
            Settings::set('default_user_name_', $request->input('default_user_name'), true);
        }
        Settings::set('user_background_maps', $request->input('user_background_maps'), true);

        Settings::set('app_login_default_plates', AdminUtils::_multipleSelectTable_order_process('selectTable:formPageMineTrait:app_login_default_plates', $request->input('app_login_default_plates')) , true);
        Settings::set('app_login_first_welcome_title', $request->input('app_login_first_welcome_title'), true);
        Settings::set('app_login_first_welcome', $request->input('app_login_first_welcome'), true);

        Settings::set('app_user_lv_watch_video', $request->input('app_user_lv_watch_video'), true);
        Settings::set('app_user_lv_publish_video', $request->input('app_user_lv_publish_video'), true);
        Settings::set('app_user_lv_open_chat', $request->input('app_user_lv_open_chat'), true);

        Settings::set('app_user_sign', AdminUtils::_table_data($request->input('app_user_sign')), true);
        Settings::set('app_sign_day_task', AdminUtils::_multipleSelectTable_order_process('selectTable:formPageMineTrait:app_sign_day_task', $request->input('app_sign_day_task')) , true);
        Settings::set('app_qa_types', $request->app_qa_types, true);
        Settings::set('app_earnings_rank_bg', $request->input('app_earnings_rank_bg'), true);

        global $__MINI_GLOBAL_PAYCODE_0__;
        if($__MINI_GLOBAL_PAYCODE_0__){
            Settings::set('app_user_about_mine_minisns_show', $request->input('app_user_about_mine_minisns_show'), true);
        }
        Settings::set('app_user_about_mine_minisns_id', $request->input('app_user_about_mine_minisns_id'), true);
        Settings::set('app_user_about_mine_list', AdminUtils::_table_data($request->input('app_user_about_mine_list')), true);

        $pages_ = [];
        $pages = $request->input('app_force_phone_pages');
        if($pages){
            foreach ($pages as $page){
                if($page){
                    $pages_[] = (int)$page;
                }
            }
        }
        Settings::set('img_get_phone_popup', $request->input('img_get_phone_popup'), true);
        Settings::set('app_force_phone_pages', $pages_, true);
        Settings::set('app_force_phone_hard', $request->input('app_force_phone_hard'), true);

        Settings::set('app_user_qrcode_way', $request->input('app_user_qrcode_way'), true);

        $app_share_poster = AdminUtils::_table_data($request->input('app_share_poster'));
        Settings::set('app_share_poster', $app_share_poster, true);

        Settings::set('app_balance_recharge_list', $app_balance_recharge_list, true);
        Settings::set('app_balance_recharge_clause', $request->input('app_balance_recharge_clause'), true);
        Settings::set('app_balance_recharge_child_refund_clause', $request->input('app_balance_recharge_child_refund_clause'), true);

        Settings::set('is_withdrawal', $request->input('is_withdrawal'), true);
        Settings::set('app_withdrawal_platform_percent', _between_($request->input('app_withdrawal_platform_percent'), 0, 100), true);
        Settings::set('app_contact_pay_platform_percent', _between_($request->input('app_contact_pay_platform_percent'), 0, 100), true);

        Settings::set('app_balance_withdrawal_force_bind_phone', $request->input('app_balance_withdrawal_force_bind_phone'), true);
        Settings::set('app_balance_withdrawal_force_real_name', $request->input('app_balance_withdrawal_force_real_name'), true);
        Settings::set('app_balance_withdrawal_force_subscribe_mp', $request->input('app_balance_withdrawal_force_subscribe_mp'), true);


        Settings::set('app_balance_withdrawal_way', $request->input('app_balance_withdrawal_way'), true);
        Settings::set('app_balance_withdrawal_day_times', $request->input('app_balance_withdrawal_day_times'), true);
        Settings::set('app_balance_withdrawal_min_once', $request->input('app_balance_withdrawal_min_once'), true);
        Settings::set('app_balance_withdrawal_max_once', $request->input('app_balance_withdrawal_max_once'), true);
        Settings::set('app_balance_withdrawal_tips', AdminUtils::list_fiele_process($request->input('app_balance_withdrawal_tips')), true);

        Settings::set('app_unban_one_hour_balance', $request->input('app_unban_one_hour_balance'), true);
        Settings::set('app_unmute_one_hour_balance', $request->input('app_unmute_one_hour_balance'), true);


        UserBgColorUpdateJob::dispatch(0, true);

        $__global_config_version__ = Settings::get('__global_config_version__', 1) + 1;
        Settings::set('__global_config_version__', $__global_config_version__);
        GatewayUtils::success('all', 13, [ 'version' => $__global_config_version__, 'file' => basename(__FILE__) ]);
        return $this->response()->success('成功！');
    }

}
